.text
Pf:
#[Save registers and update FP
    sw $fp, ($sp)	 #push fp of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
    addi $fp, $sp, 4	 #update fp value
    sw $ra, ($sp)	 #push ra of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
#]
#[Allocate space for temps
    li $t0, 4
    sub $sp, $sp, $t0
#]
#[Procedure body
R0:
    lw $v0, 4($sp)	 #save the return value to $V0
    li $t0, 4
    sub $t1, $fp, $t0
    lw $ra, ($t1)	 #restore ra
    move $sp, $fp	 #restore sp
    li $t0, 0
    sub $t1, $fp, $t0
    lw $fp, ($t1)	 #restore fp
    jr $ra	 #goto the return address
#]
.data
    .align 2
Va:
    .space 40
.text
main:
#[Save registers and update FP
    sw $fp, ($sp)	 #push fp of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
    addi $fp, $sp, 4	 #update fp value
    sw $ra, ($sp)	 #push ra of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
#]
#[Allocate space for temps
    li $t0, 4
    sub $sp, $sp, $t0
    li $t0, 4
    sub $sp, $sp, $t0
#]
#[Procedure body
    la $t0, Va	 #load addres of Va into $t0
    sw $t0, 8($sp)	 #store word in $t0 into #3
    move $t9, $sp
    lw $t0, 8($t9)	 #load #3contents
    sw $t0, ($sp)	 #push a arg of callee into stack
    li $t1, 4
    sub $sp, $sp, $t1
    jal Pf	 #goto the procedure
    addi $sp, $sp, 4
R1:
    lw $v0, 4($sp)	 #save the return value to $V0
    li $t0, 4
    sub $t1, $fp, $t0
    lw $ra, ($t1)	 #restore ra
    move $sp, $fp	 #restore sp
    li $t0, 0
    sub $t1, $fp, $t0
    lw $fp, ($t1)	 #restore fp
    jr $ra	 #goto the return address
#]
.globl Pputint
.text
Pputint:
#[Save registers and update FP
    sw $fp, ($sp)	 #push fp of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
    addi $fp, $sp, 4	 #update fp value
    sw $ra, ($sp)	 #push ra of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
#]
    li $v0, 1
    lw $a0, 4($fp)
    syscall
#[Restore registers, FP and SP
    li $t0, 4
    sub $t1, $fp, $t0
    lw $ra, ($t1)	 #restore ra
    move $sp, $fp	 #restore sp
    lw $fp, ($fp)	 #restore fp
#]
    jr $ra	 #goto the return address
.globl Pputstring
.text
Pputstring:
#[Save registers and update FP
    sw $fp, ($sp)	 #push fp of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
    addi $fp, $sp, 4	 #update fp value
    sw $ra, ($sp)	 #push ra of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
#]
    li $v0, 4
    lw $a0, 4($fp)
    syscall
#[Restore registers, FP and SP
    li $t0, 4
    sub $t1, $fp, $t0
    lw $ra, ($t1)	 #restore ra
    move $sp, $fp	 #restore sp
    lw $fp, ($fp)	 #restore fp
#]
    jr $ra	 #goto the return address
.globl Pgetint
.text
Pgetint:
#[Save registers and update FP
    sw $fp, ($sp)	 #push fp of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
    addi $fp, $sp, 4	 #update fp value
    sw $ra, ($sp)	 #push ra of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
#]
    li $v0, 5
    syscall
#[Restore registers, FP and SP
    li $t0, 4
    sub $t1, $fp, $t0
    lw $ra, ($t1)	 #restore ra
    move $sp, $fp	 #restore sp
    lw $fp, ($fp)	 #restore fp
#]
    jr $ra	 #goto the return address
.globl Pgetstring
.text
Pgetstring:
#[Save registers and update FP
    sw $fp, ($sp)	 #push fp of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
    addi $fp, $sp, 4	 #update fp value
    sw $ra, ($sp)	 #push ra of caller into stack
    li $t0, 4
    sub $sp, $sp, $t0
#]
    li $v0, 8
    lw $a0, 4($fp)
    li $a1, 80
    syscall
#[Restore registers, FP and SP
    li $t0, 4
    sub $t1, $fp, $t0
    lw $ra, ($t1)	 #restore ra
    move $sp, $fp	 #restore sp
    lw $fp, ($fp)	 #restore fp
#]
    jr $ra	 #goto the return address
